// reducer  + combineReducers  
import { combineReducers,AnyAction } from 'redux'
import * as ActionTypes from './action-types'
// 但未取其值  -> 后面没用到，引入没必要 
// tree-sharking 没用到的引入代码(黄叶子)


const initalState = {
    loading:true,
    // 分支
    home:{
        partitions:{}
    },
    search:{
        suggest:[],
        hotword:[],
        searchResult:{}
    }
    // 其他分支
        // 首页
        // 视频
        // 登陆
}

const combineSearch = (state = initalState.search,action:AnyAction) => {
    switch(action.type) {
        case ActionTypes.SET_HOTWORD:
            return {
                ...state,
                hotword:action.data
            }
        case ActionTypes.SET_SUGGEST:
            return {
                ...state,
                suggest:action.data
            }
        case ActionTypes.SET_SEARCH_RESULT:
            return {
                ...state,
                searchResult:action.data
            }
        default:
            return state
    }
}

const combineLoading = (state = initalState.loading,action:AnyAction) => {
    switch(action.type) {
        default:
            return state
    }
}

const combineHome = (state = initalState.home,action:AnyAction) => {
    switch(action.type) {
        case ActionTypes.SET_PARTITIONAS:
            return {
                ...state.partitions,
                partitions:action.data
            }
        default: 
            return state
    }
}
export default combineReducers({
    search:combineSearch,
    loading:combineLoading,
    home:combineHome
})